const initialState = {
    arr:[]
}

let tabreducer =  (state = initialState, { type, payload, payload1 }) => {
   let newobj = JSON.parse(JSON.stringify(state))
  switch (type) {

  case "getlist":
      newobj.arr = payload
    return newobj
  case "delfn" :
    newobj.arr.splice(payload,1)
    return newobj
  case "addfn" :
      newobj.arr.push(payload)
      return newobj
  case "editFn":
      newobj.arr[payload.editIndex] = payload
      return newobj
  case "searChfn" :
      let filterarr =  newobj.arr.filter((item)=>{
          return item.name.includes(payload) && item.age.toString().includes(payload1)
      })
      newobj.arr = filterarr
    
      return newobj
  default:
    return state
  }
}
export default tabreducer

